package com.deyuanyun.pic.settings.controller.base;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.settings.controller.SettingBaseController;
import com.deyuanyun.pic.settings.domain.base.CustomThreshold;
import com.deyuanyun.pic.settings.domain.base.Threshold;
import com.deyuanyun.pic.settings.service.base.ThresholdManagerService;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * “阀值设置” 管理控制类
 *
 * 方法详情：<br/>
 *
 * @author xu
 * @date  2015-12-19
 *
 * History: [hlw][2016-12-15][部分功能接口重构]
 */
@Controller
@RequestMapping("/settings/threshold")
public class ThresholdController extends SettingBaseController{

    @Autowired
    private ThresholdManagerService thresholdManagerService;

    /**
     * 跳转到阀值管理主页面
     *
     * @return
     */
    @RequestMapping("index.html")
    public ModelAndView index(){
        return forword("/settings/base/thresholdMgr");
    }

    /**
     * 查询阀值组
     */
    @RequestMapping("queryGroup.json")
    @ResponseBody
    public void queryGroup(){
        AjaxSupport.sendSuccessText("success",thresholdManagerService.queryThresholdGroup());
        return;
    }

    /**
     * 查询阀值列表
     *
     * @param code
     * @param name
     * @param groupCode
     */
    @RequestMapping("query.json")
    @ResponseBody
    public void queryThresholdList(String code,String name,String groupCode){
        Threshold threshold=new Threshold();
        if (StringUtils.isNotBlank(code)){
            threshold.setMinorCode(code);
        }
        if (StringUtils.isNotBlank(name)){
            threshold.setShortName(name);
        }
        if (StringUtils.isNotBlank(groupCode)){
            threshold.setMajorCode(groupCode);
        }
        PageJsonBean jsonBean=new PageJsonBean();
        List<CustomThreshold> sysBaseThresholdList = thresholdManagerService.queryThresholdList(threshold);
        jsonBean.setList(sysBaseThresholdList);
        AjaxSupport.sendSuccessText("success",jsonBean);
        return;
    }

    /**
     * 编辑
     *
     * @param threshold
     */
    @RequestMapping("edit.json")
    @ResponseBody
    public void editThreshold(CustomThreshold threshold){
        thresholdManagerService.editThreshold(threshold);
        AjaxSupport.sendSuccessText("success","修改成功!");
        return;
    }

}
